﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OrderWinForm
{
    public partial class Form3 : Form
    {
        public string SearchKey1 { get; set; }
        public string SearchKey2 { get; set; }
        public string OAMax { get; set; }
        public string OAMin { get; set; }
        public Form3()
        {
            InitializeComponent();
            NameTextBox.DataBindings.Add("Text", this, "SearchKey1");
            OAMaxTextBox.DataBindings.Add("Text", this, "OAMax");
            OAMinTextBox.DataBindings.Add("Text", this, "OAMin");
            OnoTextBox.DataBindings.Add("Text", this,"SearchKey2");

        }

        private void button5_Click(object sender, EventArgs e)//退出
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)//按订单号查询
        {
            Form1 form1 = (Form1)this.Owner;
            string Sono = SearchKey2;
            int m = Convert.ToInt32(Sono);
             if(OnoTextBox.Text==""|OnoTextBox.Text==null)
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData;
            }
            else
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData.Where(i => i.Ono == m);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1 form1 = (Form1)this.Owner;
            if(SearchKey1 == null||SearchKey1 == "")
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData;
            }
            else
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData.Where(m => m.Orderss.Exists(Orderdetails => Orderdetails.Goodname == SearchKey1));
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form1 form1 = (Form1)this.Owner;
            string CusName = "";
            CusName = SearchKey1;
            if (SearchKey1 == null||SearchKey1 == "")
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData;
            }
            else
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData.Where(i => i.Customer == CusName);
            }

        }

        private void button4_Click(object sender, EventArgs e)//按金额范围查询
        {
            Form1 form1 = (Form1)this.Owner;
            string Max = OAMax;
            string Min = OAMin;
            double m = Convert.ToDouble(Max);
            double n = Convert.ToDouble(Min);
            if((OAMaxTextBox.Text == "" | OAMinTextBox.Text == "") | (OAMaxTextBox.Text == null | OAMinTextBox.Text == null))
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData;
            }
            else
            {
                form1.OrderBindingSource.DataSource = form1.Orders.orderData.Where(i => i.Oamount<= m&&i.Oamount>= n);
            }
        }

        private void button6_Click(object sender, EventArgs e)//Form1复原为查询前所有数据
        {
            Form1 form1 = (Form1)this.Owner;
            form1.OrderBindingSource.DataSource = form1.Orders.orderData;
        }
    }
}
